#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<cstring>
using namespace std;
typedef long long LL;
map<string, int>mp;
const int N = 50;
int n, t, m;
int a[N], b[N];
int ans;
// vector<int>c(15);
int c[20];
void dfs(int u, int y)
{
	if (u == n + 1) {
		if (y != t)return;
		int flag = 1;
		for (int i = 1; i <= m; i++) {
			if (c[a[i]] == c[b[i]])flag = 0;
		}
		cout << "u==" << u << endl;
		cout << "y==" << y << endl;
		cout << "falg==" << flag << endl;
		ans += flag;
		return;
	}
	for (int i = 0; i <= y; i++) {
		c[u] = i;
		dfs(u + 1, max(i + 1, y));
		//int len = c.size();
		/*int sz = 0;
		int st[11] = { 0 };
		for (int x : c) {
			if (!st[x]) {
				st[x] = 1;
				sz++;
			}
		}
		dfs(u + 1, sz);
		c.pop_back();*/
	}
}
int main()
{
	cin >> n >> t >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
	}
	dfs(1, 0);
	cout << ans << endl;
	return 0;
}